package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	var waitGroup sync.WaitGroup
	waitGroup.Add(5) //设置预设数量

	for i:=0;i<5;i++ {
		go func(i int) {
			fmt.Printf("work %d is done at %s\n",i,time.Now())
			time.Sleep(time.Second)
			waitGroup.Done()
		}(i)
	}
	waitGroup.Wait() //等待预设数量全部提交
	fmt.Println("all works are done at", time.Now().String())



}
